<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>云盘首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/dist/css/layui.css"  media="all">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#checkBtn").click(function(){
                var password = $("#password").val();
                if(password==""){
                    alert("密码不能为空");
                    $("#msg").text("用户名或者密码不能为空！");
                    return false;
                }
            });
        });

    </script>
</head>
<body>
<div style="margin: 0 auto; width:60%">
    <form class="layui-form" action="/changePassword" method="post" lay-filter="example">
        <h1 style="color: #1E9FFF;text-align: center;margin-top: 100px;margin-bottom: 50px">修改密码</h1>


        <div class="layui-form-item">
            <label class="layui-form-label">新密码：</label>
            <div class="layui-input-block">
                <input type="password" name="password" id="password" placeholder="请输入密码" onblur="checkpas1();" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认新密码：</label>
            <div class="layui-input-block">
                <input type="password" name="password1" id="confirm_password" placeholder="请输入密码" onblur="checkpas()" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <span class="tip" style="color: red;">两次输入的密码不一致</span><br>
        </div>

        <div class="layui-form-item">
            <div style="text-align: center">
                <button type="submit" class="layui-btn layui-btn-normal" id="checkBtn"onclick="checkpas2();" >修改</button>
            </div>
        </div>
    </form>
    <script>
        $(".tip").hide();
        function checkpas1(){//当第一个密码框失去焦点时，触发checkpas1事件
            var pas1=document.getElementById("password").value;
            var pas2=document.getElementById("confirm_password").value;//获取两个密码框的值
            if(pas1!=pas2&&pas2!="")//此事件当两个密码不相等且第二个密码是空的时候会显示错误信息
                $(".tip").show();
            else
                $(".tip").hide();//若两次输入的密码相等且都不为空时，不显示错误信息。
        }
        function checkpas(){//当第一个密码框失去焦点时，触发checkpas2件
            var pas1=document.getElementById("password").value;
            var pas2=document.getElementById("confirm_password").value;//获取两个密码框的值
            if(pas1!=pas2){
                $(".tip").show();//当两个密码不相等时则显示错误信息
            }else{
                $(".tip").hide();
            }
        }
        function checkpas2(){//点击提交按钮时，触发checkpas2事件，会进行弹框提醒以防无视错误信息提交
            var pas3=document.getElementById("password").value;
            var pas4=document.getElementById("confirm_password").value;
            if(pas3!=pas4){
                alert("两次输入的密码不一致！");
                return false;
            }
        }
    </script>
</div>
</body>
</html>
